package dao.impl;

import dao.BaseDao;
import dao.UserinfoDao;
import entity.Userinfo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserinfoDaoImpl extends BaseDao implements UserinfoDao {

    @Override
    public Userinfo selectOne(String userAccount, String password) {
        Userinfo user=null;
        String sql="SELECT * FROM `userinfo` where userAccount=? and `password`=?";
        ResultSet rs=null;
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            rs=exeQuery(sql, new Object[]{
                    userAccount,
                    password
            },conn,ps);
            while (rs.next()){
                user=new Userinfo();
                user.setUserID(rs.getInt("userID"));
                user.setUserAccount(rs.getString("userAccount"));
                user.setPassword(rs.getString("password"));
                user.setUserName(rs.getString("userName"));
                user.setUsergender(rs.getInt("usergender"));
                user.setUserEntity(rs.getString("userEntity"));
                user.setPhone(rs.getString("phone"));
                user.setEmail(rs.getString("email"));
                user.setUsertype(rs.getInt("usertype"));
                user.setWechat(rs.getString("wechat"));
//                return rs.getInt(1);
            }

        } catch (Exception exception) {
            exception.printStackTrace();
        }finally {
            closeAll(rs,ps,conn);
        }
        return user;
    }
}
